package com.techsoul.common.core.pojo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.techsoul.common.core.pojo.vo.CategoryVo;
import com.techsoul.common.core.pojo.vo.MenuVo;
import com.techsoul.common.core.pojo.vo.OrgVo;
import com.techsoul.common.core.pojo.vo.RegionVo;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Treeselect树结构实体类
 *
 * @author liuen
 */
@Data
public class TreeSelect implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 节点ID
     */
    private String id;

    /**
     * 节点名称
     */
    private String label;

    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelect> children;

    public TreeSelect() {}

    public TreeSelect(OrgVo orgVo) {
        this.id = orgVo.getId();
        this.label = orgVo.getOrgName();
        if (orgVo.getChildren() != null) {
            this.children = orgVo.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
        } else {
            this.children = new ArrayList<>();
        }
    }

    public TreeSelect(MenuVo menuVo) {
        this.id = menuVo.getId();
        this.label = menuVo.getMenuName();
        if (menuVo.getChildren() != null) {
            this.children = menuVo.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
        } else {
            this.children = new ArrayList<>();
        }
    }

    public TreeSelect(CategoryVo sysMenuVo) {
        this.id = sysMenuVo.getId();
        this.label = sysMenuVo.getCategoryName();
        if (sysMenuVo.getChildren() != null) {
            this.children = sysMenuVo.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
        } else {
            this.children = new ArrayList<>();
        }
    }

    public TreeSelect(RegionVo node) {
        this.id = node.getId();
        this.label = node.getRegionName();
        if (node.getChildren() != null) {
            this.children = node.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
        } else {
            this.children = new ArrayList<>();
        }
    }

}
